import React, {useState, useEffect} from 'react';
import action from '../../store/actions/receiving';
import {connect} from 'react-redux';
import {Pagination} from 'antd';
import {confirmReceipt} from '../../api';
import Header from './Header';
import ReceivingList from './ReceivingList';


function Receiving(props) {

  useEffect(() => {
    props.RECEIVING_LIST();
  }, []);

  // 确认收货
  const tempConfirmReceipt = async refund_no => {
    await confirmReceipt(refund_no);
    await props.RECEIVING_LIST(props.current);
  };

  // 分页改变
  const pageChange = page => {
    props.RECEIVING_LIST(page);
  };

  return (
    <div className={'Receiving'}>
      <Header/>
      <ReceivingList tempConfirmReceipt={tempConfirmReceipt} receivingList={props.receivingList}/>
      <Pagination
        current={props.current}
        onChange={pageChange}
        total={props.pageCount ? props.pageCount : 1}
        style={{textAlign: 'center', marginTop: '20px'}}
        pageSize={10}
        hideOnSinglePage
      />
    </div>
  );
}

const mapStateToProps = state => state.receiving;
export default connect(mapStateToProps, action)(Receiving);
